/*
 * globalDefinitions.h
 *
 *  Created on: 15-Sep-2011
 *      Author: prat
 *      Modified By:Amy, Jan
 * 		
 */

#ifndef GLOBALDEFINITIONS_H_
#define GLOBALDEFINITIONS_H_

#include "globalConstants.h"
#include "globalHeaders.h"
//#define trace(...) trace(__FILE__, __LINE__, __VA_ARGS__)
//frame structure
extern void* buffer;//buffer Pool
extern  map<long, long> pageMap;

typedef struct database{
	char dbName[DB_NAME];
	long dbIndex;
	FILE *dbFP;
}db;

typedef struct frameStruct
{
public:
	long frameNumber;
	bool dirty;
	//long pinCount;
	db* dbIndex;
	unsigned long refCount;//0 is lowest priority
	//long frameNumber;
	unsigned char pageData[1];
}Frame;

//Page structure (should it be a class or struct??)
typedef struct pageStruct
{

	/*
	 * Priority = 0 for dbheader
	 * 1 for dpPage
	 * 2 for dbPage
	 */
	int priority;
	long pageNumber;
	long nextPage;//TBD if needed
	long CFS; //contiguous free space
	char pageData[1];
}Page;



typedef struct sysTable {
	char *tableName;
	int tableId;
	long tablePage; //pointer to the directory page
}sysTable;

typedef struct sysCols {
	int noOfAttributes;
	char **colName;
	char *colType[1]; //get it from globalConstants.h
	int sizeOfAttribute;
	int precision; //for float data
	bool isNull;
	bool isIndexAttribute;
	bool hasDefaultValue;
	void *defaultValue;
	long tablePage; //pointer to the directory page
}sysCols;

// J: New Structure Added
typedef struct keyPartStruct
		{
				char attributeName[50];
				char attributeType[20];
				int attributeSize;
		}keyPart1;

// J: Updated Structure
typedef struct sysIndexStructure
		{
			int indexID;
			int tableID; // id of the table to which the index belongs
			long ptrToPageContainingRootofTree;
			long tableDirPage;
			int isAsc;
			int fanoutFactor;
			keyPart1 compositeKeyParts[2];
}sysIndex;
// J: Updated
typedef struct RIDStruct
{
	long pageNo;
	int value; // slot Number
}RID;

//J: Updated
typedef struct tupleStruct
{
	int tupleId;
	unsigned int recLen;
	RID recordId;
	unsigned char recData[1];
}tuple;

typedef struct colMega{
	char *colName;
	char *colType; //get it from globalConstants.h
	int sizeOfAttribute;
	int precision; //for float data
	bool isNull;
	bool isIndexAttribute;
	bool hasDefaultValue;
	void *defaultValue;
}colMegaStructure;

#endif /* GLOBALDEFINITIONS_H_ */
